package com.hzyb.shopEvaluation.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.hzyb.shopEvaluation.model.SubmitComment;
import com.hzyb.shopEvaluation.service.ShopEvaluationService;

@RestController
@RequestMapping("/shopEvaluation")
public class ShopEvaluationController {

	private static final Logger Logger=LoggerFactory.getLogger(ShopEvaluationController.class);

	@Resource
	private ShopEvaluationService shopEvaluationService;

	@RequestMapping("/getEvaluationList")
	public Map<String, Object> getEvaluationList(@RequestParam String commoditySid){
		return shopEvaluationService.getShopEvaluationByCommoditySid(commoditySid);
	}

	@RequestMapping("/submitComment")
	public Map<String, Object> submitComment(SubmitComment submitComment){
		Map<String, Object> map=new HashMap<>();
		map.put("status", "fail");
		if(submitComment==null) {
			map.put("error_msg", "form is null!!");
			return map;
		}
		try {
			shopEvaluationService.submitComment(submitComment);
			map.put("status", "success");
		} catch (Exception e) {
			Logger.error(e.toString());
			map.put("error_msg", e.getMessage());
		}
		return map;
	}

	@RequestMapping("/test")
	public ModelAndView gotoTest() {
		ModelAndView modelAndView=new ModelAndView("评价提交");
		return modelAndView;
	}

}
